package springframework.common;

import com.qumoyugo.springframework.beans.BeansException;
import com.qumoyugo.springframework.beans.factory.config.BeanPostProcessor;
import springframework.bean.UserService;

/**
 * @author Cedric
 * @date 2021/11/24 17:07
 * @description BeanPostProcessor实现
 */
public class MyBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessorBeforeInitialization(Object bean, String beanName) throws BeansException {
        if (beanName.equals("userService")) {
            UserService userService = (UserService) bean;
            userService.setLocation("环球中心");
        }
        return bean;
    }

    @Override
    public Object postProcessorAfterInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }
}
